package com.sreader.sreader4j;

import java.io.Serializable;
import java.util.Locale;

import com.vaadin.terminal.ExternalResource;
import com.vaadin.terminal.ThemeResource;
import com.vaadin.ui.AbsoluteLayout;
import com.vaadin.ui.MenuBar;
import com.vaadin.ui.MenuBar.MenuItem;
import com.vaadin.ui.Window;

public class ApplicationMenuBar implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	/**
	 * 
	 */
	
	

	
	private MenuBar menubar;;
	private Locale currentLocaleValue;
	private Window mainWindow;
	//private FeuilleDeCalculCroise feuilleCroise;
	private Messages messages;
	private AbsoluteLayout mainWindowAbsolutLayout;
	public  MenuBar.Command barCommand;

	
	public ApplicationMenuBar(Locale defaultLocale, Window mainWindow){
		setCurrentLocaleValue(defaultLocale);
		setMessages(new Messages("FeuilleDeCalcul",defaultLocale));
		this.mainWindow = mainWindow;
		menubar = new MenuBar();
		mainWindowAbsolutLayout = new AbsoluteLayout();
		mainWindowAbsolutLayout.setWidth("750.0px");
		mainWindowAbsolutLayout.setHeight("950.0px");
		
		//feuilleCroise = new FeuilleDeCalculCroise(defaultLocale, mainWindow);;
		
		final MenuBar.MenuItem optionsMenu = menubar.addItem(this.messages.getString("menuOptions")
														,new ThemeResource("img/settings.png"),null);
	
		//options.setStyleName("file");
		barCommand = new MenuBar.Command() {
			
			/**
			 * 
			 */
			private static final long serialVersionUID = 1L;

	
			@Override
			public void menuSelected(MenuItem selectedItem) {
				// TODO Auto-generated method stub
				//getWindow().showNotification(selectedItem.getText());
				//System.out.println("itemID :" + selectedItem.getId() + " itemText :" + selectedItem.getText());
				int itemId = selectedItem.getId();
				System.out.println("id. " + itemId);
				switch (itemId){
					/*case 3:
						//start analyse individuelle
						final Window individualWindow = new Window(getMessages().getString("analyseIndividuelle"));
						individualWindow.setName(getMessages().getString("analyseIndividuelWindowName"));
						ApplicationMenuBar.this.mainWindow.getApplication().getWindow(individualWindow.getName());
						break;*/
					case 3:
						//start analyse croisée getMessages().getString("calculCroiseWindowName")
						final Window croiseWindow = new Window(getMessages().getString("analyseCroisee"));
						croiseWindow.setName(getMessages().getString("calculCroiseWindowName"));
						ApplicationMenuBar.this.mainWindow.getApplication().getWindow(croiseWindow.getName());
						//menubar.getApplication().getMainWindow().addWindow(croiseWindow);
						break;
					case 4:
						ApplicationMenuBar.this.mainWindow.getApplication().removeWindow(getMainWindow());
						break;
					default: break;
				}
			}
		};
		
		//MenuBar.MenuItem analyseIndividuelle = optionsMenu.addItem(this.messages.getString("analyseIndividuelle")
		//														,barCommand);
		//options.addSeparator();
		MenuBar.MenuItem analyseCroisee      = optionsMenu.addItem(this.messages.getString("analyseCroisee")
																,barCommand);
		
		//MenuBar.MenuItem nombresDeDestin     = optionsMenu.addItem(this.messages.getString("nombresDeDestin")
		//										,barCommand);
		MenuBar.MenuItem quit     = optionsMenu.addItem(this.messages.getString("quit")
				,barCommand);
	}
	
	public void setCurrentLocaleValue(Locale currentLocaleValue) {
		this.currentLocaleValue = currentLocaleValue;
	}
	
	public String getCurrentLocaleValue() {
		
		return "_" + currentLocaleValue.toString();
	}
	
	public Messages getMessages() {
		return messages;
	}

	public void setMessages(Messages messages) {
		this.messages = messages;
	}
	
	public MenuBar getApplicationMenuBar(){
		return this.menubar;
	}
	public Locale getCurrentLocale(){
		return this.currentLocaleValue;
	}
	
	public Window getMainWindow(){
		return mainWindow;
	}
	
}
